package com.icinfo.cloud.provider.punish.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.page.PageResponse;
import com.icinfo.cloud.provider.punish.approval.dto.*;
import com.icinfo.cloud.provider.punish.approval.vo.*;
import com.icinfo.cloud.provider.punish.service.ApprovalService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseBasicInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseIllegalParkingRecordVo;
import com.icinfo.cloud.provider.punish.vo.CaseInfoVo;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 审批任务控制器
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/app/audit")
public class AuditController {

    @Resource
    private ApprovalService approvalService;

    /**
     * 查询待审批列表
     * @param auditQueryPageDto
     * @return
     */
    @PostMapping("/getWaitAuditList")
    public Result<PageResponse<AuditInfoListVo>> getWaitAuditList(  @RequestBody AuditQueryPageDto auditQueryPageDto){
        return approvalService.getWaitAuditList(auditQueryPageDto);
    }

    /**
     * 查询已审批列表
     * @param auditQueryPageDto
     * @return
     */

    @PostMapping("/getOffAuditList")
    public Result<PageResponse<AuditInfoListVo>> getOffAuditList(@Validated @RequestBody AuditQueryPageDto auditQueryPageDto){
        return approvalService.getOffAuditList(auditQueryPageDto);
    }

    /**
     * 案件详情 案件信息--包含主表信息，办案人员信息，案由信息，当事人信息
     * @param caseId 案件id
     * @author lxj
     * @date 2022-04-02 09:33
     */
    @GetMapping("/getCaseInfo")
    @ApiOperation(value = "【V1.0.0】描述：公用-根据案件id查询案件信息", httpMethod = "GET")
    public Result<CaseInfoVo> getCaseInfo(@RequestParam String caseId, @RequestParam(value = "isCaseAdditionalApproval",required = false) String isCaseAdditionalApproval) {
        CaseInfoVo vo = null;
        if (Constant.STRING_1.equals(isCaseAdditionalApproval)) {
//            vo = approvalService.getCaseAdditionalInfo(caseId);
        } else {
            vo = approvalService.getCaseInfo(caseId);
        }
        return Result.success(vo);
    }

    /**
     * 查询下个节点处理人员列表
     * 案件caseId
     * @param dto
     * @return
     */
    @PostMapping("/getNextNodeUser")
    public Result<List<NextAuditUserVo>> getNextNodeUser(@Validated @RequestBody AuditNextUserQueryDto dto){
        return approvalService.getNextNodeUser(dto);
    }

    /**
     * 查询历史审批内容
     *
     * @param dto
     * @return {@link Result< List< String>>}
     */
    @PostMapping("/getApprovalOpinionHis")
    public Result<List<String>> getApprovalOpinionHis(@Validated @RequestBody ApprovalOpinionHisQueryDto dto){
        return  approvalService.getApprovalOpinionHis(dto);
    }

    /**
     * 【V1.0.0】审批详情 案件信息 办案人员信息 当事人信息（不使用）
     *
     * @param caseId 案件id
     * @return {@link Result< CaseBasicInfoVo >} 案件简要基础信息
     * @author xiangyuyu
     * @date 2022-02-22 09:33
     */
    @PostMapping("/getCaseBasicInfo")
    @ApiOperation(value = "【V1.0.0】描述：公用-根据案件id查询案件简要基础信息", httpMethod = "POST")
    public Result<CaseBasicInfoVo> getCaseBasicInfo(@RequestParam String caseId) {
       return approvalService.getCaseBasicInfo(caseId);
    }


    /**
     * 查询审批链日志
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditChain")
    public Result<List<AuditInfoChainLogVo>> getAuditChain(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto) throws ParseException {
        return approvalService.getAuditChain(auditDetailDocumentQueryDto);
    }


    /**
     * 查询审批链头部
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditChainTop")
    public Result<AuditInfoChainLogTopVo> getAuditChainTop(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){

        return approvalService.getAuditChainTop(auditDetailDocumentQueryDto);
    }
    /**
     * 审批详情文书信息
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditDocDetail")
    public Result<AuditInfoVo> getAuditDocDetail(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){
        return approvalService.getAuditDocDetail(auditDetailDocumentQueryDto);
    }

    /**
     * 审批通过
     * @param
     * @return
     */
    @PostMapping("/doAgreeAudit")
    public Result doAgreeAudit(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        return approvalService.doAgreeAudit(approvalAuditDto);
    }


    /**
     * 审批退回
     * @param
     * @return
     */
    @PostMapping("/doReturnAudit")
    public Result doReturnAudit(@Validated @RequestBody ApprovalReturnlAuditDto approvalAuditDto){
        return approvalService.doReturnAudit(approvalAuditDto);
    }
    /**
     * 获取审批相关状态
     * @author liyafeng
     * @date 2022/8/9
      * @param approvalQueryDto
     * @return {@link Result< String>}
     */
    @PostMapping("/getApprovalInfo")
    public Result<ApprovalInfoVo> getApprovalInfo(@Validated @RequestBody ApprovalQueryDto approvalQueryDto){
        return approvalService.getApprovalInfo(approvalQueryDto);
    }

    /**
     * 通用提交审批接口，该文书需要审批调用
     * @param
     * @return
     */
    @PostMapping("/documentGeneralSubmit")
    public Result documentGeneralSubmit(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        return approvalService.documentGeneralSubmit(dto);
    }
    /**
     * 通用提交自动审批接口，该文书需要审批调用
     * @param
     * @return
     */
    @PostMapping("/documentGeneralSubmitAuto")
    public Result documentGeneralSubmitAuto(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        return approvalService.documentGeneralSubmitAuto(dto);
    }

    /**
     * 速结程序查询当前审批信息
     * @param
     * @return
     */
    @PostMapping("/getFastCaseApprovalInfo")
    public Result<FastCaseApprovalInfoVo> getFastCaseApprovalInfo(@Validated @RequestBody FastCaseApprovalDto dto){
        return  approvalService.getFastCaseApprovalInfo(dto);
    }
    /**
     * 速结程序查询是否审批完成
     * @param
     * @return
     */
    @PostMapping("/getFastCaseIsApprovalPass")
    public Result<String> getFastCaseIsApprovalPass(@Validated @RequestBody FastCaseApprovalDto dto){
        return  approvalService.getFastCaseIsApprovalPass(dto);
    }

    /**
     * 获取机动车违停记录列表
     * @param request
     * @return
     */
    @PostMapping("/getIllegalParkingList")
    public Result<PageResponse<CaseIllegalParkingRecordVo>> getIllegalParkingList(@RequestBody CaseIllegalParkingRecordRequest request){
        return approvalService.getIllegalParkingList(request);
    }

    /**
     * 新增机动车违停记录
     * @param dto
     * @return
     */
    @PostMapping("/saveIllegalParkingRecord")
    public Result saveIllegalParkingRecord(@RequestBody CaseIllegalParkingRecordDto dto){
        return approvalService.saveIllegalParkingRecord(dto);
    }

    /**
     * 修改机动车违停记录
     * @param dto
     * @return
     */
    @PostMapping("/updateIllegalParkingRecord")
    public Result updateIllegalParkingRecord(@RequestBody CaseIllegalParkingRecordDto dto){
        return approvalService.updateIllegalParkingRecord(dto);
    }

    /**
     * 删除机动车违停记录
     * @param dto
     * @return
     */
    @PostMapping("/deleteIllegalParkingRecord")
    public Result deleteIllegalParkingRecord(@RequestBody CaseIllegalParkingRecordDto dto){
        return approvalService.deleteIllegalParkingRecord(dto);
    }

    /**
     * 获取机动车违停记录详情
     * @param dto
     * @return
     */
    @PostMapping("/getIllegalParkingRecordDetail")
    public Result<CaseIllegalParkingRecordVo> getIllegalParkingRecordDetail(@RequestBody CaseIllegalParkingRecordDto dto){
        return approvalService.getIllegalParkingRecordDetail(dto);
    }
    /**
     * 合并提交审批接口，该文书需要审批调用（简案快办合并提交使用）
     * @author liyafeng
     * @date 2023/4/24
     * @param dto
     * @return {@link Result}
     */
    @PostMapping("/documentGeneralMergeSubmit")
    public Result documentGeneralMergeSubmit(@Validated @RequestBody ApprovalGeneralSubmitDto dto) {
        return approvalService.documentGeneralMergeSubmit(dto);
    }
    /**
     * 审批通过（合并审批）
     * @param
     * @return
     */
    @PostMapping("/doAgreeAuditMerge")
    public Result doAgreeAuditMerge(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        return approvalService.doAgreeAuditMerge(approvalAuditDto);
    }
    /**
     * 审批退回(合并审批)
     * @param
     * @return
     */
    @PostMapping("/doReturnAuditMerge")
    public Result doReturnAuditMerge(@Validated @RequestBody ApprovalReturnlAuditDto approvalAuditDto){
        return approvalService.doReturnAuditMerge(approvalAuditDto);
    }





    }
